package com.itheima.hmshopping.dubbo.apiImpl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.hmshopping.dubbo.api.SmsCouponProductCategoryRelationServiceApi;
import com.itheima.hmshopping.dubbo.mapper.SmsCouponProductCategoryRelationMapper;
import com.itheima.hmshopping.entity.SmsCouponProductCategoryRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponProductCategoryRelationServiceApiImpi implements SmsCouponProductCategoryRelationServiceApi {


    @Autowired
    private SmsCouponProductCategoryRelationMapper smsCouponProductCategoryRelationMapper;
    //新增优惠券和产品分类关系表
    @Override
    public void insertList(List<SmsCouponProductCategoryRelation> productCategoryRelationList) {
        for (SmsCouponProductCategoryRelation smsCouponProductCategoryRelation : productCategoryRelationList) {
            smsCouponProductCategoryRelationMapper.insert(smsCouponProductCategoryRelation);
        }
    }

    //删除
    @Override
    public void delect(Integer id) {
        Long aLong = Convert.toLong(id);
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SmsCouponProductCategoryRelation::getCouponId,aLong);
        smsCouponProductCategoryRelationMapper.delete(lambdaQueryWrapper);
    }

    //查询
    @Override
    public List<SmsCouponProductCategoryRelation> selectById(Integer id) {
        Long aLong = Convert.toLong(id);
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SmsCouponProductCategoryRelation::getCouponId,aLong);
        List<SmsCouponProductCategoryRelation> smsCouponProductCategoryRelations = smsCouponProductCategoryRelationMapper.selectList(lambdaQueryWrapper);
        return smsCouponProductCategoryRelations;
    }
}
